<%@ page pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/includes/directives/page.jspf"%>
<%@ include file="/WEB-INF/views/includes/directives/taglib.jspf"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<%@ include file="/WEB-INF/views/includes/include_js_css.jspf"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title><fmt:message key="items_list_jsp.title" /></title>
</head>
<body>
	<div id="main_container">
		<%@ include file="/WEB-INF/views/includes/header.jspf"%>
		<%@ include file="/WEB-INF/views/includes/category_menu.jspf"%>
		<div id="content">
			<table>
				<c:set var="role">${userBean.userRole}</c:set>
				<c:choose>
					<c:when test="${role == 'ADMIN'}">
						<%-- ===================================================================================
									Table head for admin
						===================================================================================--%>
						<tr>
							<td>id</td>
							<td><fmt:message key="items_list_jsp.table.header.item_name" /></td>
							<td></td>
							<td></td>
						</tr>

					</c:when>

					<c:otherwise>
						<%-- ===================================================================================
									Table head for users
						===================================================================================--%>
						<tr>
							<td><fmt:message key="items_list_jsp.table.header.item_name" /></td>
							<td><fmt:message
									key="items_list_jsp.table.header.item_price" /></td>
						</tr>
					</c:otherwise>
				</c:choose>

				<c:forEach var="item" items="${itemsList}">

					<c:choose>
						<c:when test="${role == 'ADMIN'}">
							<%-- ===================================================================================
									Item list for admin
							===================================================================================--%>
							<tr>
								<td>${item.id}</td>
								<td>${item.name}</td>
								<td><a href="main?command=edit_item&itemId=${item.id}">
										<fmt:message key="items_list_jsp.table.edit_item" />
								</a></td>
								<td><a href="main?command=remove_item&itemId=${item.id}">
										<fmt:message key="items_list_jsp.table.remove_item" />
								</a></td>
							</tr>
						</c:when>

						<c:otherwise>
							<%-- ===================================================================================
									Item list for users
							===================================================================================--%>
							<c:choose>
								<c:when test="${item.isAvailable}">
									<tr>
										<td><a href="main?command=show_item&itemId=${item.id}">${item.name}</a></td>
										<td><fmt:formatNumber type="number" value="${item.price}" /> <fmt:message key="view_item_jsp.label.hryn" /></td>
									</tr>
								</c:when>
								<c:otherwise>
									<tr>
										<td><a href="main?command=show_item&itemId=${item.id}">${item.name}</a></td>
										<td><fmt:formatNumber type="number" value="${item.price}" /> <fmt:message key="view_item_jsp.label.hryn" /><span class="out_of_stock"> <fmt:message
													key="items_list_jsp.table.item_out_of_stock" />
										</span>
										</td>
									</tr>
								</c:otherwise>
							</c:choose>
						</c:otherwise>
					</c:choose>
				</c:forEach>
			</table>
		</div>
		<div id="free_space"></div>
	</div>
	<%@ include file="/WEB-INF/views/includes/footer.jspf"%>
</body>
</html>